package ru.st.selenium.pages;

import org.openqa.selenium.By;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.support.FindBy;

import static org.openqa.selenium.support.ui.ExpectedConditions.*;

public class LoginPage extends AnyPage {

	public LoginPage(PageManager pages) {
		super(pages);
	}

	@FindBy(id = "login")
	private WebElement loginField;

	@FindBy(id = "pass")
	private WebElement passwordField;

	@FindBy(name = "subm")
	private WebElement submitButton;

	public LoginPage setloginField(String text) {
		loginField.sendKeys(text);
		return this;
	}

	public LoginPage setPasswordField(String text) {
		passwordField.sendKeys(text);
		return this;
	}

	public void clickSubmitButton() {
		submitButton.click();
	}

	public LoginPage ensurePageLoaded() { // метод ensurePageLoaded реализоман при помощи поиска элемента
										 // на странице
		super.ensurePageLoaded();
		wait.until(presenceOfElementLocated(By.name("login")));
		wait.until(presenceOfElementLocated(By.name("pass")));
		return this;
	}
}